const MYSQL = require("../../sql/mysql");
const DayJs = require("dayjs")
/**
 * 添加接口权限
 * @param {object} params
 * @param {string} params.id 角色id
 * @param {string} params.path 接口id
 * @returns {Promise<{code:string,msg:string}>}
 */
module.exports = async (params = {}) => {
    try {

        let sqlName = "auth_path"

        let {
            name, path, comment, type
        } = params
    
        let create_date = DayJs(Date.now()).valueOf();
        let state = 1
        let query = `INSERT INTO ${sqlName} SET ? `;
        await MYSQL.promise().query(query, {
            name, path, comment, state, type,
            create_date
        });
        return {
            code: 0,
            msg: "操作成功",
        };
    } catch (error) {
        console.log(error);
        throw {
            code: 500,
            msg: "添加接口权限失败",
        };
    }

};
